<?php


namespace app\api\controller;

use app\api\library\order\createOrder;
use app\api\library\order\orderList;
use app\api\library\order\orderNum;
use app\api\library\order\orderDetail;
use app\api\library\order\orderPay;
use app\api\library\order\wechatPay;
use app\api\library\order\allInPay;
use app\api\library\order\wechatNotify;
use app\api\library\order\refundNotify;
use app\api\library\order\allInPayNotify;
use app\api\library\order\orderRefund;
use app\api\library\order\cancelRefund;
use app\api\library\order\confirmOrder;
use app\api\library\order\collageList;
use app\api\library\order\getOrderExpress;
use app\api\model\MallOrder;
use app\common\controller\IndexController;
use think\facade\Config;
use think\facade\Db;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\AddReceiverPlugin;
use Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin;

class Order extends IndexController
{
    public function getWechatPayInfo()
    {
        $order = Db::name('mall_order')->where('id', 75)->find();
        MallOrder::resolvePromotion(34, $order);
        
    }
    /**
     * 创建订单
     */
    public function createOrder()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['goodsId', 'gi', 'int'],
            ['specId', 'si', 'int'],
            ['shareUserId', 'sui', 'int'],
            ['collageId', 'ci', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        createOrder\V::run($param);
    }
    /**
     * 订单列表
     */
    public function orderList()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['status', 'ss', 'int'],
            ['page', 'pe', 'int', 1],
            ['limit', 'lt', 'int', 3],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        orderList\V::run($param);
    }
    /**
     * 订单列表
     */
    public function orderNum()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['status', 'ss', 'int'],
            ['page', 'pe', 'int', 1],
            ['limit', 'lt', 'int', 3],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        orderNum\V::run($param);
    }
    /**
     * 订单详情
     */
    public function orderDetail()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['orderId', 'oi', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        orderDetail\V::run($param);
    }
    /**
     * 支付订单
     */
    public function orderPay()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['openId', 'opi', 'str'],
            ['orderId', 'oi', 'int'],
            ['addressId', 'ai', 'int'],
            ['remark', 'rk', 'str'],
            ['wechatPayAmount', 'wpa', 'int'],
            ['balancePayAmount', 'bpa', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        orderPay\V::run($param);
    }
    /**
     * 支付订单
     */
    public function wechatPay()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['openId', 'opi', 'str'],
            ['orderId', 'oi', 'int'],
            ['addressId', 'ai', 'int'],
            ['remark', 'rk', 'str'],
            ['wechatPayAmount', 'wpa', 'int'],
            ['balancePayAmount', 'bpa', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        wechatPay\V::run($param);
    }
    /**
     * 支付订单
     */
    public function allInPay()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['openId', 'opi', 'str'],
            ['orderId', 'oi', 'int'],
            ['addressId', 'ai', 'int'],
            ['remark', 'rk', 'str'],
            ['wechatPayAmount', 'wpa', 'int'],
            ['balancePayAmount', 'bpa', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        allInPay\V::run($param);
    }
    /**
     * 微信异步响应
     */
    public function wechatNotify()
    {
        wechatNotify\V::run();
    }
    /**
     * 微信异步响应
     */
    public function refundNotify()
    {
        refundNotify\V::run();
    }
    
    /**
     * 异步响应
     */
    public function allInPayNotify()
    {
        allInPayNotify\V::run();
    }
    /**
     * 退款
     */
    public function orderRefund()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['orderId', 'oi', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        orderRefund\V::run($param);
    }
    /**
     * 退款
     */
    public function cancelRefund()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['orderId', 'oi', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
    
    
        cancelRefund\V::run($param);
    }
    /**
     * 确认收货
     */
    public function confirmOrder()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['orderId', 'oi', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        confirmOrder\V::run($param);
    }
    /**
     * 获取物流信息
     */
    public function getOrderExpress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['orderId', 'oi', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        getOrderExpress\V::run($param);
    }
    /**
     * 订单列表
     */
    public function collageList()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['status', 'ss', 'int'],
            ['page', 'pe', 'int', 1],
            ['limit', 'lt', 'int', 3],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        collageList\V::run($param);
    }
    
    
}